package com.lbloca.locate.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ZoomControls;

import androidx.appcompat.widget.Toolbar;

import com.baidu.location.BDLocation;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.gyf.immersionbar.ImmersionBar;
import com.lbloca.locate.R;
import com.lbloca.locate.beans.FriendBean;
import com.lbloca.locate.ui.base.BaseActivity;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.OnClick;

public class FriendLoactionActivity extends BaseActivity {

    @BindView(R.id.bmapView)
    MapView mMapView;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_myloc)
    TextView mTvMyLoc;
    @BindView(R.id.id_toolbar)
    Toolbar mToolbar;

    private BaiduMap mBaiduMap;
    private FriendBean mFiendBean;



    @Override
    protected int getLayoutId() {
        return R.layout.activity_friend_loction;
    }

    @Override
    protected void initView() {
//        View child = mMapView.getChildAt(1);
//        if (child != null && (child instanceof ImageView || child instanceof ZoomControls)) {
//            child.setVisibility(View.INVISIBLE);
//        }
//        mMapView.showScaleControl(false);
        initMapStatus();
    }

    @Override
    protected void initData() {
       Bundle bundle =  getIntent().getExtras();
        mFiendBean = (FriendBean) bundle.get("friendBean");
        if(mFiendBean!=null){
            tvAddress.setText(mFiendBean.getAddress());
            tvTime.setText(mFiendBean.getUpdatedate());
            mTvMyLoc.setText(mFiendBean.getPhone());
        }
    }

    @Override
    protected void initEvents() {
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }





    private void initMapStatus() {
        mBaiduMap = mMapView.getMap();

        MapStatus.Builder builder = new MapStatus.Builder();
        builder.zoom(18.0f);
        mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
        LatLng point = new LatLng(31.2959, 121.129779);
        MapStatusUpdate status2 = MapStatusUpdateFactory.newLatLng(point);
        mBaiduMap.setMapStatus(status2);
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.drawable.location_friend);
        OverlayOptions option = new MarkerOptions()
                .position(point) //必传参数
                .icon(bitmap) //必传参数
                .draggable(true)
                .flat(true)
                .alpha(0.5f);
        mBaiduMap.addOverlay(option);


    }


    public static void start(Context context, FriendBean friendBean) {
        Intent intent = new Intent(context, FriendLoactionActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("friendBean",friendBean);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }


    public void onPause() {
        super.onPause();
        if (mMapView != null)
            mMapView.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        if (mMapView != null)
            mMapView.onResume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mBaiduMap != null)
            mBaiduMap.setMyLocationEnabled(false);
        mBaiduMap = null;
        if (mMapView != null)
            mMapView.onDestroy();
        mMapView = null;
    }
    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .statusBarDarkFont(true)
                .navigationBarDarkIcon(true)
                .titleBar(mToolbar)
                .init();
    }

}
